package com.github.livebase.util.base;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName DateUtil
 * @description:
 * @author: biao532
 * @create: 2023-12-08 10:02
 * @Version 1.0
 **/
public class DateUtil {
    public static final SimpleDateFormat HH_mm = new SimpleDateFormat("HH:mm");
    public static String format(SimpleDateFormat dateFormat, Date date) {
        return dateFormat.format(date);
    }
    public static String format(String dateFormat, Date date) {
        return format(new SimpleDateFormat(dateFormat), date);
    }

    public static int day(Date date) {
        return Integer.valueOf(DateUtil.format(new SimpleDateFormat("yyyyMMdd"), date));
    }
    public static int dayOffsetToday(int offsetDay) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DATE, offsetDay);
        Date date = c.getTime();
        return day(date);
    }
    public static int today() {
        return dayOffsetToday(0);
    }

    public static long now() {
        return System.currentTimeMillis();
    }

    public static boolean betweenAnd(long time, long start, long end) {
        if (start > end) {
            end = start ^ end;
            start = start ^ end;
            end = start ^ end;
        }
        return time >= start && time < end;
    }
}
